home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c
- Path: howland.reston.ans.net!torn!sq!utzoo!spenford!henry
- From: Henry Spencer <henry@zoo.toronto.edu>
- Subject: Re: integral types in switch expressions
- References: <4eb5r1$b04@news.tuwien.ac.at>
- Sender: henry%spenford@zoo.toronto.edu (Henry Spencer)
- Organization: SP Systems, Toronto
- Date: Fri, 1 Mar 1996 04:47:54 GMT
- Message-ID: <DnKnzv.8t6%spenford@zoo.toronto.edu>
-
- In article <4eb5r1$b04@news.tuwien.ac.at> schwarz@mips.complang.tuwien.ac.at (Konrad Schwarz) writes:
- >I was surprised to learn that constant pointer expressions are
- >not allowed in case labels and that the expression in a switch statement
- >must be an integral type. (The reason for the exclusion of floating point
- >is obvious to me). I am interested in the technical reasons for this.
-
- Well, the practical reason is that C compilers have traditionally
- disallowed it and nobody made a convincing case for changing this.
-
- The technical reason for disallowing it is that doing even a vaguely
- clever implementation of switch requires knowing the values of the case
- labels at compile time. The values of pointer expressions are typically
- not known until link time; on systems using dynamic linking, they may not
- be known until run time. When the values are not known at compile time,
- it's hard to implement the switch as anything other than a series of
- ifs... and there is no point in writing that as a switch.
- --
- Space will not be opened by always | Henry Spencer
- leaving it to another generation. --Bill Gaubatz | henry@zoo.toronto.edu
-